package 多线程.复习.volatile关键字;

import java.util.Scanner;

public class NonVolatile {
    private static  class Count{
        volatile int count = 0;
    }

    public static void main(String[] args) {
        Count count = new Count();
        Thread t1 = new Thread(() -> {
            while (count.count == 0){

            }
            System.out.println(count.count + ":退出循环");
        },"t1");
        t1.start();
        Thread t2 = new Thread(() -> {
            try {
                Thread.sleep(1000);
//                    count.count++;
                Scanner sc = new Scanner(System.in);
                System.out.println("count = ");
                count.count = sc.nextInt();
                System.out.println("t2的JJM中的count值为："+count.count);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },"t2");
        t2.start();
    }
}
